package com.app.service.impl;
import com.app.db.mongo.PrimaryMongoConfig;
import com.app.db.mongo.SecondaryMongoConfig;
import com.app.db.mongodb.m1.MongoUserEntityM1;
import com.app.db.mongodb.m2.MongoUserEntityM2;
import com.app.service.MongoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
import java.util.Date;


/**
 * @author liuli
 */
@Service
public class MongoServiceImpl  implements MongoService {
    @Autowired
    /** 默认主 可以不用添加*/
    @Qualifier(PrimaryMongoConfig.MONGO_TEMPLATE)
    private MongoTemplate masterMongoTemplate;

    @Qualifier(SecondaryMongoConfig.MONGO_TEMPLATE)
    @Autowired
    private MongoTemplate secondMongoTemplate;

    @Override
    public void saveMultiple() {
        MongoUserEntityM1 mongoUserEntityM1 =  new MongoUserEntityM1();
        mongoUserEntityM1.setId(System.currentTimeMillis());
        mongoUserEntityM1.setAge("20");
        mongoUserEntityM1.setName("姓名-m1"+System.currentTimeMillis());
        mongoUserEntityM1.setMoney(20.1);
        mongoUserEntityM1.setMakeDate(new Date());
        masterMongoTemplate.save(mongoUserEntityM1);

        MongoUserEntityM2 mongoUserEntityM2 =  new MongoUserEntityM2();
        mongoUserEntityM2.setId(System.currentTimeMillis());
        mongoUserEntityM2.setAge("20");
        mongoUserEntityM2.setName("姓名-m2"+System.currentTimeMillis());
        mongoUserEntityM2.setMoney(20.1);
        mongoUserEntityM2.setMakeDate(new Date());
        secondMongoTemplate.save(mongoUserEntityM2);
    }
}
